using System;
using System.Collections.Generic;
using System.Text;

namespace SP
{
    /// <summary>
    /// Base class of IFusion
    /// </summary>
    public abstract class AbstractFusion : IFusion
    {
        public AbstractFusion()
        {
            mPPs = new List<Preprocessor>();
            mParams = new List<IParameter>();
            mEnabled = true;
        }

        public List<Preprocessor> Preprocessors
        {
            get { return mPPs; }
        }

        public List<IParameter> Parameters
        {
            get { return mParams; }
        }

        public abstract string Name { get; }

        public abstract string Desc { get;}

        public abstract Stage Stage { get; }

        public abstract int UVChannelCount { get;}

        public abstract void Code(StringBuilder b, string platform);

        public Preprocessor GetPreprocessor(string name)
        {
            foreach (Preprocessor p in mPPs)
                if (p.Name.Equals(name))
                    return p;

            return null;
        }

        public IParameter GetParameter(string name)
        {
            foreach (IParameter p in mParams)
                if (p.Name.Equals(name))
                    return p;

            return null;
        }
        public bool Enabled
        {
            get { return mEnabled; }
            set { mEnabled = value; }
        }

        public IFusion SetEnabled(bool val)
        {
            this.Enabled = val;
            return this;
        }

        

        protected void AddPreprocessor(Preprocessor p)
        {
            mPPs.Add(p);
        }

        protected void AddParameter(IParameter p)
        {
            mParams.Add(p);
        }

        protected void AddLine(StringBuilder b, string line)
        {
            b.Append("\t" + line + "\n");
        }

        private List<Preprocessor> mPPs;
        private List<IParameter> mParams;
        private bool mEnabled;
    }
}
